package com.mdd.admin.controller.setting;

import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.plugin.ai.AiDriver;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author XYueong
 * @date 2023-12-06
 * @description: TODO
 */
@RestController
@RequestMapping("api/setting/ai")
@Api(tags = "ai设置")
public class SettingAiController {
    @Resource
    AiDriver aiDriver;

    @PostMapping("/keySetup")
    @ApiOperation(value = "配置ai")
    public AjaxResult<Object> question(@RequestBody Map<String, Object> params) {
        String key = (String) params.get("key");
        String chatModel = (String) params.get("chatModel");
        String proxyHost = (String) params.get("proxyHost");
        Integer proxyPort = params.get("proxyPort") == null ? null : Integer.valueOf((String) params.get("proxyPort"));

        if (proxyHost != null) {
            aiDriver.setChatGptApiKey(key, chatModel, proxyHost, proxyPort);
        } else {
            aiDriver.setChatGptApiKey(key, chatModel);
        }


        return AjaxResult.success();
    }
}
